import React from 'react';
import { Button, Breadcrumb } from 'antd';

const Index = React.createClass({

  contextTypes: {
    router: React.PropTypes.object
  },

  getInitialState() {
    return {
      btnTxt: '返回',
      lastPath: '',
      nextPath: ''
    }
  },

  handleRouter() {
    console.log(location.pathname)
    let path = location.pathname;
    let lastUrl = this.state.lastPath;
    let nextUrl = this.state.nextPath;
    let txtName = ( path == lastUrl) ? '返回' : '添加';
    let goPathUrl = ( path == lastUrl) ? nextUrl : lastUrl;
    this.context.router.push(goPathUrl);
    this.setState({btnTxt: txtName});
  },

  render () {
    console.log(location.href)
    let breadcrumb = this.props;
    return (
      <div className="nav-bar">
        <Breadcrumb separator="-" >
          <Breadcrumb.Item>{breadcrumb.item}</Breadcrumb.Item>
          <Breadcrumb.Item>{this.state.btnTxt == '添加' ? '列表' : '添加'}</Breadcrumb.Item>
        </Breadcrumb>
        <Button className="ant-button" type="primary" htmlType="button" onClick={this.handleRouter}>{this.state.btnTxt}</Button>
      </div>
    );
  }
});

export default Index